<!--包房管理 -->
<template>
  <div class="admin-body">
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>包房管理</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    <el-row style="padding: 15px">

      <el-row class="main">
        <el-row  style="min-height: 40px;display: flex;">
          <el-col  style="margin-bottom: 5px;" align="left">
            <el-input v-model="key" clearable style="width: 300px;" placeholder="输入关键词查询" class="kz_search">
              <el-button slot="append" type="primary"  @click="getstart()">搜索</el-button>
            </el-input>
          </el-col>
          <el-col  style="margin-bottom: 5px;" align="right">
            <!--<el-button type="primary" @click="goHref('classified')" style="">分类管理</el-button>-->
            <el-button type="primary" @click="add()" style="">添加包房</el-button>
          </el-col>
        </el-row>
        <!--表格-->
        <el-table
          select-on-indeterminate
          ref="multipleTable"
          border
          align="left"
          :data="tableData">
          <el-table-column
            type="index"
            label="序号"
            width="50">
          </el-table-column>
          <el-table-column
            prop="room_name"
            label="包房名称">
          </el-table-column>
          <el-table-column
            label="包房类型">
            <template slot-scope="scope">
             {{pdlx(scope.row.type)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="room_size"
            label="适用人数">
          </el-table-column>
          <el-table-column
            prop="rule"
            label="使用规则">
          </el-table-column>
          <el-table-column
            label="适用开始时间">
            <template slot-scope="scope">
              {{formatDate(scope.row.begin_time)}}
            </template>
          </el-table-column>
          <el-table-column
            label="适用结束时间">
            <template slot-scope="scope">
              {{formatDate(scope.row.over_time)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="session_type"
            label="场次">
            <!--<template slot-scope="scope">-->
              <!--{{pdlx1(scope.row.session_type)}}-->
            <!--</template>-->
          </el-table-column>
          <el-table-column
            prop="number"
            label="包房数量">
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <el-button @click="changeMes(scope.row.id,0)" style="color: red" size="small" type="text">
                删除
              </el-button>
              <el-button @click="edit(scope.row)"  style="" size="small" type="text">
                修改
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <el-row style="margin-top: 20px">
          <el-col :xs="24" :sm="24" :md="24" :lg="24" align="right">
            <el-pagination
              style="text-align: right;margin-bottom:70px;"
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="dataTotal">
            </el-pagination>
          </el-col>
        </el-row>
      </el-row>
    </el-row>
    <el-dialog title="新增" :visible.sync="addVisible" width="500px" :modal-append-to-body="false">
      <el-form :model="adddata" :rules="addrules" ref="adddata">
        <el-form-item label="包房名字：" :label-width="formLabelWidth" prop="room_name">
          <el-input v-model="adddata.room_name" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="包房适用人数：" :label-width="formLabelWidth" prop="room_size">
          <el-input v-model="adddata.room_size" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="包房类型：" :label-width="formLabelWidth" prop="type">
          <el-select style="width: 220px;" v-model="adddata.type" clearable  placeholder="请选择包房类型">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="包房数量：" :label-width="formLabelWidth" prop="number">
          <el-input v-model="adddata.number" clearable>
            <template slot="append">个</template>
          </el-input>
        </el-form-item>
        <el-form-item label="使用规则：" :label-width="formLabelWidth" prop="rule">
          <el-input v-model="adddata.rule" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="场次选择：" :label-width="formLabelWidth" prop="session_type">
          <el-checkbox-group v-model="adddata.session_type">
            <el-checkbox  label="下午场" ></el-checkbox>
            <el-checkbox  label="黄金场" style="margin-left: 0px;"></el-checkbox>
            <el-checkbox  label="午夜场" style="margin-left: 0px;"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="使用开始时间：" :label-width="formLabelWidth" prop="begin_time">
          <el-date-picker
            v-model="adddata.begin_time"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="使用结束时间：" :label-width="formLabelWidth" prop="over_time">
          <el-date-picker
            v-model="adddata.over_time"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="SubmitAdd('adddata')">提交审核</el-button>
        <el-button @click="addVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="编辑" :visible.sync="editVisible" width="500px" :modal-append-to-body="false">
      <el-form :model="editdata" :rules="editrules" ref="editdata">
        <el-form-item label="包房名字：" :label-width="formLabelWidth" prop="room_name">
          <el-input v-model="editdata.room_name" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="包房适用人数：" :label-width="formLabelWidth" prop="room_size">
          <el-input v-model="editdata.room_size" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="包房类型：" :label-width="formLabelWidth" prop="type">
          <el-select style="width: 220px;" v-model="editdata.type" clearable  placeholder="请选择包房类型">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="包房数量：" :label-width="formLabelWidth" prop="number">
          <el-input v-model="editdata.number" clearable>
            <template slot="append">个</template>
          </el-input>
        </el-form-item>
        <el-form-item label="使用规则：" :label-width="formLabelWidth" prop="rule">
          <el-input v-model="editdata.rule" clearable>
          </el-input>
        </el-form-item>
        <el-form-item label="场次选择：" :label-width="formLabelWidth" prop="session_type">
          <el-checkbox-group v-model="editdata.session_type">
            <el-checkbox  label="下午场" ></el-checkbox>
            <el-checkbox  label="黄金场" style="margin-left: 0px;"></el-checkbox>
            <el-checkbox  label="午夜场" style="margin-left: 0px;"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="使用开始时间：" :label-width="formLabelWidth" prop="begin_time">
          <el-date-picker
            v-model="editdata.begin_time"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="使用结束时间：" :label-width="formLabelWidth" prop="over_time">
          <el-date-picker
            v-model="editdata.over_time"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="SubmitEdit('editdata')">提交审核</el-button>
        <el-button @click="editVisible = false">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
  import MyOneUpload from '../../components/MyOneUpload'
  export default {
    name: "PrivateRoom",
    components:{
      MyOneUpload
    },
    mounted() {
      // if (!this.$store.state.login.in) {
      //   this.$router.push({name: "login", params: {userId: 123}})
      // }
      this.getstart()
    },
    data() {
      return {
        pageSize: 10,
        page: 1,
        dataTotal: 0,
        tableData:[],
        addVisible:false,
        formLabelWidth:'130px',
        adddata:{
          shop_id:'',
          type:'',
          number:'',
          room_name:'',
          session_type	:[],
          room_size	:'',
          rule	:'',
          begin_time	:'',
          over_time	:'',
        },
        addrules:{
          type: [
            {required: true, message: '请输入账号', trigger: 'blur'}
          ],
          number: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          room_name: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          session_type: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          room_size: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          rule: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          begin_time: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          over_time: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
        },
        options: [
          {
            value: '1',
            label: '中小包'
          },
          {
            value: '2',
            label: '大包'
          },
          {
            value: '3',
            label: '豪包'
          },
        ],
        type:'',
        editVisible:false,
        editdata:{
          id:'',
          type:'',
          number:'',
          room_name:'',
          session_type	:[],
          room_size	:'',
          rule	:'',
          begin_time	:'',
          over_time	:'',
        },
        editrules:{
          type: [
            {required: true, message: '请输入账号', trigger: 'blur'}
          ],
          number: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          room_name: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          session_type: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          room_size: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          rule: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          begin_time: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
          over_time: [
            {required: true, message: '请输入用户名', trigger: 'blur'}
          ],
        },
        key:'',
      }
    },
    computed:{
      userdata(){
        return this.$store.state.login.user
      }
    },
    methods: {
      pdlx(type){
        let dateArr = ['小包','中小包','大包','豪包',];
        return dateArr[type]
      },
      pdlx1(type){
        let dateArr = ['上午场','下午场','黄金场','午夜场',];
        return dateArr[type]
      },
      edit(data){
        console.log(data)
        this.editdata = JSON.parse(JSON.stringify(data))
        this.editdata.id = this.editdata.id
        if (this.editdata.session_type) {
          this.editdata.session_type = this.editdata.session_type.split(',')
        }

        this.editdata.begin_time = this.editdata.begin_time * 1000
        this.editdata.over_time = this.editdata.over_time * 1000
        this.editVisible = true
      },
      restPassword(id){
        this.restVisible = true
        this.restdata.platform_id = id
      },
      SubmitAdd(formName){
        let thi = this
        thi.adddata.shop_id = thi.$store.state.login.user.id
        thi.adddata.session_type = thi.adddata.session_type.join(',')
        thi.adddata.begin_time = Math.round(thi.adddata.begin_time)/1000
        thi.adddata.over_time = Math.round(thi.adddata.over_time)/1000
        thi.$refs[formName].validate((valid) => {
          if (valid) {
            thi.mySubmit('addRoom', thi.adddata).then(function (code) {
              if (code==200) {
                thi.addVisible = false
                thi.getstart()
              }
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      SubmitEdit(formName){
        let thi = this
        thi.editdata.session_type = thi.editdata.session_type.join(',')
        thi.editdata.begin_time = Math.round(thi.editdata.begin_time)/1000
        thi.editdata.over_time = Math.round(thi.editdata.over_time)/1000
        thi.$refs[formName].validate((valid) => {
          if (valid) {
            thi.mySubmit('editRoom', thi.editdata).then(function (code) {
              if (code==200) {
                thi.editVisible = false
                thi.getstart()
              }
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      details(data){
        // this.$store.state.login.platformId = data
        if (data == 1){
          this.$router.push({name:'privateRoomDetail'})
        } else if (data == 2) {
          this.$router.push({name:'shoppingMallDetail'})
        }else {
          this.$router.push({name:'comment'})
        }


      },
      add(){
        this.addVisible = true
      },
      //绑定表格数据，分页
      getstart() {
        let thi = this
        const prams = {
          page:thi.page,
          pageSize:thi.pageSize,
          shop_id: thi.$store.state.login.user.id,
          key:thi.key,
        }
        thi.mySelectAll('roomList',prams).then(function (value) {
          thi.tableData = value.data
          thi.dataTotal = value.Total
        })
      },

      //选择展示数量
      handleSizeChange(val) {
        this.pageSize = val
        this.getstart()
      },
      //分页
      handleCurrentChange(val) {
        this.page = val
        this.getstart()
      },
      //状态改变提示
      changeMes(id, state) {
        var heeh = '该'
        var caozuo = '禁用'
        if (id.length > 1) {
          heeh = '这些'
        }
        if (state == 0) {
          caozuo = '删除'
        }
        let thi = this
        thi.$confirm('此操作将'+caozuo + heeh+'包房', '是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        }).then(() => {
          thi.submitState(id,state)
        }).catch(() => {
          thi.$message({
            type: 'info',
            message: '已取消'
          });
        });
      },
      //删除
      submitState(id,state) {
        let thi = this
        const por = {
          shop_id: thi.$store.state.login.user.id,
          id: id,
          state: state,
        }
        console.log(por)
        thi.mySubmit('editRoomState', por).then(function (code) {
          if (code == 200) {
            thi.getstart()
          }
        })
      },
    }
  }

</script>

<style scoped>
  .main {
    background-color: white;
    min-height: 500px;
    padding: 10px;
    border: #EDEDED 1px solid;
    border-radius: 5px;
  }
  .el-row{
    /*防止页面抖动*/
    width: calc(100% - 2px) !important;
  }
  .cmap{
    width: 100%;
    height: 400px;
    margin-bottom: 10px;
  }
  .search-cont{
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 999999;
  }
  .mapTxt {
    text-align: center;
    width: 220px;
    padding: 4px;
    overflow: hidden;
    font-size: 14px;
    font-weight: bold;
    white-space: normal;
    margin-left: 40px;
    margin-top: 40px;
  }
</style>
